﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.PermissionBLL;

namespace Tauren.Business.Core.Controllers
{ 
    [Route("api/permission"), ApiVersion("1.0")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        private IPermissionService service;
        public PermissionController(IPermissionService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 分页获取权限信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult(true);

        /// <summary>
        /// 获取字段数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/config/{type}")]
        public IActionResult Config([FromRoute] string type) => service.Config(type).ToJsonResult(true);

        /// <summary>
        /// 获取列表模板数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns> 
        [HttpPost, Route("v{version:apiVersion}/template/{key}")]
        public IActionResult Template([FromRoute] string key) => service.Template(key).ToJsonResult();
        /// <summary>
        /// 根据主键获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}")]
        public IActionResult Get([FromRoute] long id) => service.Get(AutoID: id).ToJsonResult();

        /// <summary>
        /// 新增信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.Permission_Input data) => service.Insert(data).ToJsonResult();

        /// <summary>
        /// 根据主键删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] long id) => service.Delete(AutoID: id).ToJsonResult(true);

        /// <summary>
        /// 根据主键禁用数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id}")]
        public IActionResult Enable([FromRoute] long id) => service.Enable(AutoID: id).ToJsonResult(true);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/edit")]
        public IActionResult Edit([FromBody] Entity.Input.Permission_Input data) => service.Edit(data).ToJsonResult(true);

    }
}
